home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_023 / ver30 / tty / 7300 / tty.c next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  272 lines

  1. /*
  2.  * Name:    MicroEMACS
  3.  *        AT&T UNIX PC 7300/3b1 terminal display
  4.  * Version:    29
  5.  * Last edit:    25-Apr-86
  6.  * By:        {sun, amdahl, mtxinu, cbosgd}!rtech!daveb
  7.  *
  8.  * This is nearly the ansi/tty.c, except the 7300 has broken scroll
  9.  * region support with index and reverse index.  Instead we do it
  10.  * with parameterized insert/delete lines.
  11.  *
  12.  * It also has "smart" support for the window system.
  13.  */
  14. #include    "def.h"
  15.  
  16. #define    BEL    0x07            /* BEL character.        */
  17. #define    ESC    0x1B            /* ESC character.        */
  18. #define    LF    0x0A            /* Line feed.            */
  19.  
  20. extern    int    ttrow;
  21. extern    int    ttcol;
  22. extern    int    tttop;
  23. extern    int    ttbot;
  24. extern    int    tthue;
  25.  
  26. int    tceeol    =    3;        /* Costs, ANSI display.        */
  27. int    tcinsl    =     17;
  28. int    tcdell    =    16;
  29.  
  30. /*
  31.  * Initialize the terminal when the editor
  32.  * gets started up. This is a no-op on the ANSI
  33.  * display.
  34.  */
  35. ttinit()
  36. {
  37. }
  38.  
  39. /*
  40.  * Clean up the terminal, in anticipation of
  41.  * a return to the command interpreter. This is a no-op
  42.  * on the ANSI display. On the SCALD display, it sets the
  43.  * window back to half screen scrolling. Perhaps it should
  44.  * query the display for the increment, and put it
  45.  * back to what it was.
  46.  */
  47. tttidy()
  48. {
  49. }
  50.  
  51. /*
  52.  * Move the cursor to the specified
  53.  * origin 0 row and column position. Try to
  54.  * optimize out extra moves; redisplay may
  55.  * have left the cursor in the right
  56.  * location last time!
  57.  */
  58. ttmove(row, col)
  59. {
  60.     if (ttrow!=row || ttcol!=col) {
  61.         ttputc(ESC);
  62.         ttputc('[');
  63.         asciiparm(row+1);
  64.         ttputc(';');
  65.         asciiparm(col+1);
  66.         ttputc('H');
  67.         ttrow = row;
  68.         ttcol = col;
  69.     }
  70. }
  71.  
  72. /*
  73.  * Erase to end of line.
  74.  */
  75. tteeol()
  76. {
  77.     ttputc(ESC);
  78.     ttputc('[');
  79.     ttputc('K');
  80. }
  81.  
  82. /*
  83.  * Erase to end of page.
  84.  */
  85. tteeop()
  86. {
  87.     ttputc(ESC);
  88.     ttputc('[');
  89.     ttputc('J');
  90. }
  91.  
  92. /*
  93.  * Make a noise.
  94.  */
  95. ttbeep()
  96. {
  97.     ttputc(BEL);
  98.     ttflush();
  99. }
  100.  
  101. /*
  102.  * Convert a number to decimal
  103.  * ascii, and write it out. Used to
  104.  * deal with numeric arguments.
  105.  */
  106. asciiparm(n)
  107. register int    n;
  108. {
  109.     register int    q;
  110.  
  111.     q = n/10;
  112.     if (q != 0)
  113.         asciiparm(q);
  114.     ttputc((n%10) + '0');
  115. }
  116.  
  117. /*
  118.  * Insert a block of blank lines onto the
  119.  * screen, using parameterized insert and delete line commands.
  120.  *
  121.  * Deal with the one
  122.  * line case, which is a little bit special, with special
  123.  * case code. Put all of the back index commands out
  124.  * in a block. The SCALDstation loses the position
  125.  * of the cursor.
  126.  */
  127. ttinsl(row, bot, nchunk)
  128. {
  129.     if (row == bot) {            /* Funny case.        */
  130.         if (nchunk != 1)
  131.             abort();
  132.         ttmove(row, 0);
  133.         tteeol();
  134.     } else {                /* General case.    */
  135.         ttwindow(row, bot);
  136.  
  137.         /* delete the lines that are going away */
  138.         ttmove(bot + 1 - nchunk , 0);
  139.         ttputc(ESC);
  140.         ttputc('[');
  141.         asciiparm( nchunk );
  142.         ttputc('M');
  143.  
  144.         /* add the lines */
  145.         ttmove(row, 0);
  146.         ttputc(ESC);
  147.         ttputc('[');
  148.         asciiparm( nchunk );
  149.         ttputc('L');
  150.     }
  151. }
  152.  
  153. /*
  154.  * Delete a block of lines, with the uppermost
  155.  * line at row "row", in a screen slice that extends to
  156.  * row "bot". The "nchunk" is the number of lines that have
  157.  * to be deleted. Watch for the pathalogical 1 line case.
  158.  * Done using delete and insert line commands.
  159.  */
  160. ttdell(row, bot, nchunk)
  161. {
  162.     if (row == bot) {            /* Funny case.        */
  163.         if (nchunk != 1)
  164.             abort();
  165.         ttmove(row, 0);
  166.         tteeol();
  167.     } else {                /* General case.    */
  168.  
  169.         /* delete the lines that are going away */
  170.         ttmove(row, 0);
  171.         ttputc(ESC);
  172.         ttputc('[');
  173.         asciiparm( nchunk );
  174.         ttputc('M');
  175.  
  176.         /* insert new lines to fill the empty space */
  177.         ttmove(bot + 1 - nchunk , 0);
  178.         ttputc(ESC);
  179.         ttputc('[');
  180.         asciiparm( nchunk );
  181.         ttputc('L');
  182.  
  183.     }
  184. }
  185.  
  186. /*
  187.  * This routine sets the scrolling window
  188.  * on the display to go from line "top" to line
  189.  * "bot" (origin 0, inclusive). The caller checks
  190.  * for the pathalogical 1 line scroll window that
  191.  * doesn't work right, and avoids it. The "ttrow"
  192.  * and "ttcol" variables are set to a crazy value
  193.  * to ensure that the next call to "ttmove" does
  194.  * not turn into a no-op (the window adjustment
  195.  * moves the cursor).
  196.  */
  197. ttwindow(top, bot)
  198. {
  199.     /* No-op on 7300 */
  200. }
  201.  
  202. /*
  203.  * Switch to full screen scroll. This is
  204.  * used by "spawn.c" just before is suspends the
  205.  * editor, and by "display.c" when it is getting ready
  206.  * to exit. This function gets to full screen scroll
  207.  * by sending a DECSTBM with default parameters, but
  208.  * I think that this is wrong. The SRM seems to say
  209.  * that the default for Pb is 24, not the size of the
  210.  * screen, which seems really dumb. Do I really have
  211.  * to read the size of the screen as in "ttresize"
  212.  * to do this right?
  213.  */
  214. ttnowindow()
  215. {
  216.     /* No-op on 7300 */
  217. }
  218.  
  219. /*
  220.  * Set the current writing color to the
  221.  * specified color. Watch for color changes that are
  222.  * not going to do anything (the color is already right)
  223.  * and don't send anything to the display.
  224.  * The rainbow version does this in putline.s on a
  225.  * line by line basis, so don't bother sending
  226.  * out the color shift.
  227.  */
  228. ttcolor(color)
  229. register int    color;
  230. {
  231.     if (color != tthue) {
  232.         if (color == CTEXT) {        /* Normal video.    */
  233.             ttputc(ESC);
  234.             ttputc('[');
  235.             ttputc('m');
  236.         } else if (color == CMODE) {    /* Reverse video.    */
  237.             ttputc(ESC);
  238.             ttputc('[');
  239.             ttputc('7');
  240.             ttputc('m');
  241.         }
  242.         tthue = color;            /* Save the color.    */
  243.     }
  244. }
  245.  
  246. /*
  247.  * This routine is called by the
  248.  * "refresh the screen" command to try and resize
  249.  * the display. The new size, which must be deadstopped
  250.  * to not exceed the NROW and NCOL limits, it stored
  251.  * back into "nrow" and "ncol". Display can always deal
  252.  * with a screen NROW by NCOL. Look in "window.c" to
  253.  * see how the caller deals with a change.
  254.  */
  255. ttresize()
  256. {
  257. # if 0
  258.     register int    c;
  259.     register int    newnrow;
  260.     register int    newncol;
  261.  
  262.     else if (newnrow > NROW)
  263.         newnrow = NROW;
  264.     if (newncol < 1)
  265.         newncol = 1;
  266.     else if (newncol > NCOL)
  267.         newncol = NCOL;
  268.     nrow = newnrow;
  269.     ncol = newncol;
  270. # endif
  271. }
  272.